﻿using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;

namespace Dal
{
    public class DbAreaDal
    {
        public DbAreaDal() { }

        #region Select
        public static DataSet Select()
        {
            string sql = "select a.* from DbArea a ";
            return SqlHelper.Select(sql);
        }

        public static DbArea Select(Int32 AreaID)
        {
            DbArea DbArea = null;
            string sql = @"select a.* from DbArea a  where a.AreaID= {0} ";
            sql = string.Format(sql, AreaID);
            DataSet ds = SqlHelper.Select(sql);
            if (SqlHelper.HasRow(ds))
                DbArea = new DbArea(ds.Tables[0].Rows[0]);
            return DbArea;
        }

        public static DataSet Select(string where)
        {
            if (where.Trim().ToLower().StartsWith("where"))
                where = where.Substring(5);
            if (!where.Trim().ToLower().StartsWith("and") && where.Trim().Length > 0)
                where = " and " + where;
            string sql = "select a.* from DbArea a  where 1=1 " + where;
            return SqlHelper.Select(sql);
        }

        #endregion Select
    }
}
